var app = "/fzxy";

function local_get(method, callback, query) {
    var url = app + "/" + method;
    if (query == null || query == undefined || query == "") {
    } else {
        url = url + "?" + query;
    }
    
    console.log("url: " + url);
    $.get(url, callback);
}

function local_post(method, data, callback) {
    var url = app + "/" + method;
    console.log("url: " + url);
    $.post(url, data, callback, "json");
}

// callback()
function api_login(username, password, callback) {
    console.log("email: " + username + ",password: " + password);
    local_post("login", {email:username, password:password}, function(result, status) {
        var str = JSON.stringify(result);
        console.log("Ret: " + str + "\nStatus: " + status);
        if (result.errcode != 0) {
            callback(false, result.errmsg);
        } else {
            // 登录成功
            callback(true);
        }
    });
}

// 得到服务器状态信息
function api_get_server_info(callback) {
    console.log("api_get_server_info");
    local_post("get_server_info", {}, function(result, status) {
        var str = JSON.stringify(result);
        console.log("Ret: " + str + "\nStatus: " + status);
        if (result.errcode != 0) {
            callback(false, result.errmsg);
        } else {
            // 登录成功
            callback(true, "ok", result.data);
        }
    });
}

// 得到操作
// userid 角色id
// start 从哪个位置开始
// size 数量
// 回调
function api_get_operate(userid, start, size, callback) {
    console.log("userid:%s, start:%d, size:%d", userid, start, size);
    local_post("get_operate_data", {userid:userid, start:start, size:size}, function(result, status) {
        var str = JSON.stringify(result)
        console.log("Ret: " + str + "\nStatus: " + status);
        if (result.errcode != 0) {
            callback(false, result.errmsg);
        } else {
            // 登录成功
            callback(true, "ok", result.data);
        }
    })
}